$(function () {
    // todos 获取新闻列表
    $.get('http://www.liulongbin.top:3006/api/news', function ({ status, msg, data }) {


        const str = data.map(({ id, cmtcount, img, source, tags, time, title }) => {
            // console.log(data[id - 1].tags.split(','))
            const arr = data[id - 1].tags.split(',').map(function (e) {
                //遍历只要写一个就好 ，自己会走完全程的 
                return `
                <span>${e}</span> 
                `
            }).join('')

            // console.log(time)

            console.log(time);
            const dt = new Date(time)
            const t = dt.toLocaleString()
            //tolocaleTimeString
            //toLocaleDateSring
            console.log(t)

            const m = t.replace(/[/]/g, '-')
            console.log(m)

            return `
                <div class="news-item">
                <img class="thumb" src='http://www.liulongbin.top:3006${img}' alt="" />
                <div class="right-box">
                  <h1 class="title">${title}</h1>
                  <div class="tags">
                   ${arr}
                  </div>
                  <div class="footer">
                    <div>
                      <span>${source}</span>&nbsp;&nbsp;
                      <span>${m}</span>
                    </div>
                    <span>评论数：${cmtcount}</span>
                  </div>
                </div>
              </div>
                `
        }).join('')
        $('#news-list').html(str)
    })



})
